/*----------------------------------------
	1.2.2) 用户设置
	----------------------------------------*/
	var Admin;
	if (!Admin) Admin = {};
	Admin.us = {};
	
	/**
	 * main gui of user setting
	 */
	Admin.us.main = function()
	{
		$(".content_block").spin();
		$.ajax({
			url: us_path + "user_setting_form",
			success: function(html) {
				$(".content_block").spin(false);
				$(".content_block").html(html);
			}
		});
	}
	
	Admin.us.submit_user_setting = function(user_setting_array)
	{
		$(".content_block").spin();
		$.ajax({
			url: us_path + "user_setting_submit",
			dataType: 'json',
			data: {user_setting_array: user_setting_array},
			success: function(data) {
				$(".content_block").spin(false);
				$(".message").css({ "display": "none" });
				if (data == 'succeed') {
					$(".message.success.main").css({ "display": "block" });
				}
			}
		});
	}
	
	Admin.us.change_pwd = function(old_pwd, pwd, re_pwd)
	{
		$("#us_change_pwd_dialog").spin();
		$.ajax({
			url: us_path + "user_change_pwd",
			dataType: 'json',
			data: {old_pwd: old_pwd, pwd: pwd, re_pwd: re_pwd},
			success: function(data) {
				Admin.us.change_pwd_is_succeed = false;
				$("#us_change_pwd_dialog").spin(false);
				$(".message").css({ "display": "none" });
				switch (data)
				{
				case 'null_old_password_error':
					$('#change_pwd_msg').html("<strong style='background: url(/images/icon/attention.png) no-repeat; color: #f60;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请输入原始密码</strong>");
					break;
				case 'old_password_length_error':
					$('#change_pwd_msg').html("<strong style='background: url(/images/icon/attention.png) no-repeat; color: #f60;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;登录密码长度应为4~10字节</strong>");
					break;
				case 'null_new_password_error':
					$('#change_pwd_msg').html("<strong style='background: url(/images/icon/attention.png) no-repeat; color: #f60;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请输入修改密码</strong>");
					break;
				case 'new_password_length_error':
					$('#change_pwd_msg').html("<strong style='background: url(/images/icon/attention.png) no-repeat; color: #f60;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;登录密码长度应为4~10字节</strong>");
					break;
				case 'null_re_password_error':
					$('#change_pwd_msg').html("<strong style='background: url(/images/icon/attention.png) no-repeat; color: #f60;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请输入确认密码</strong>");
					break;
				case 're_password_length_error':
					$('#change_pwd_msg').html("<strong style='background: url(/images/icon/attention.png) no-repeat; color: #f60;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;登录密码长度应为4~10字节</strong>");
					break;
				case 'conf_password_match_error':
					$('#change_pwd_msg').html("<strong style='background: url(/images/icon/attention.png) no-repeat; color: #f60;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;确认密码与修改密码不匹配</strong>");
					break;
				case 'old_password_match_error':
					$('#change_pwd_msg').html("<strong style='background: url(/images/icon/attention.png) no-repeat; color: #f60;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;原始密码错误</strong>");
					break;
				case 'succeed':
					Admin.us.main();
					Admin.us.change_pwd_is_succeed = true;
					break;
				}
				
			}
		});
	}
	
	// listen to 'create' button
	$("#change_pwd").live('click', function() {
		$("#change_pwd_msg").empty();
		$("#us_change_pwd_dialog :password").val("");
		$("#us_change_pwd_dialog").dialog("open");
	});
	
	// listen to 'submit user setting' button
	$(".us#modify_submit").live('click', function() {
		var is_empty = 0;
		$(":text").each(function() {
			if ($(this).val() == '') {
				alert("请填写您的'" + $(this).prev().html() + "'");
				is_empty = 1;
				return false;
			}
		});
		$("select").each(function() {
			if ($(this).val() == '') {
				alert("请选择您的'" + $(this).prev().html() + "'");
				is_empty = 1;
				return false;
			}
		});
		
		if (is_empty == 1) { return; }
		
		var user_setting_array = new Array();
		var k = 0;
		$(":text").each(function() {
			if (!user_setting_array[k]) {
				user_setting_array[k] = new Array();
			}
			user_setting_array[k][0] = $(this).attr("id");
			user_setting_array[k][1] = $(this).val();
			k++;
		});
		$("select").each(function() {
			if (!user_setting_array[k]) {
				user_setting_array[k] = new Array();
			}
			user_setting_array[k][0] = $(this).attr("id");
			user_setting_array[k][1] = $(this).val();
			k++;
		});
		
		Admin.us.submit_user_setting(user_setting_array);
		setTimeout("$('.message').slideUp(200)", 3000);
	});
	